package com.zhuozhou.jdyc.base;

import android.view.MenuItem;
import android.widget.TextView;

import androidx.annotation.ColorRes;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.databinding.ViewDataBinding;

import com.zhuozhou.jdyc.R;

/**
 * Created by fz on 2020/11/19 14:13
 * describe:自定义toolbar样式baseActivity
 */
public abstract class BaseToolbarActivity<VM extends BaseViewModel, VDB extends ViewDataBinding> extends BaseActivity<VM, VDB> {

    @Override
    protected boolean hasToolBar() {
        return true;
    }

    /**
     * 给toolbar添加菜单
     *
     * @param menuStr  按钮文字
     * @param listener 按钮点击事件
     */
    protected void addMenu(String menuStr, Toolbar.OnMenuItemClickListener listener) {
        if (toolbarBind == null) {
            return;
        }
        toolbarBind.mainBar.inflateMenu(R.menu.menu_more);
        MenuItem menuItem = getToolbar().getMenu().findItem(R.id.toolbar_more);
        TextView textView = (TextView) menuItem.getActionView();
        textView.setText(menuStr);
        toolbarBind.mainBar.setOnMenuItemClickListener(listener);
    }

    /**
     * 给toolbar添加菜单
     *
     * @param menuStr  按钮文字
     * @param colorRes 按钮文字颜色
     * @param listener 按钮点击监听事件
     */
    protected void addMenu(String menuStr, @ColorRes int colorRes, Toolbar.OnMenuItemClickListener listener) {
        if (toolbarBind == null) {
            return;
        }
        toolbarBind.mainBar.inflateMenu(R.menu.menu_more);
        MenuItem menuItem = getToolbar().getMenu().findItem(R.id.toolbar_more);
        TextView textView = (TextView) menuItem.getActionView();
        textView.setTextColor(ContextCompat.getColor(this, colorRes));
        textView.setText(menuStr);
        toolbarBind.mainBar.setOnMenuItemClickListener(listener);
    }
}
